package com.cosmosource.core.response;

import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Collection;

/**
 * @author mahe
 * @date 2022/9/26 21:02
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ResponsePagedEntity<T extends Collection<?>> extends ResponseEntity<T> implements Serializable {

    private Long total;

    public ResponsePagedEntity(@NotNull ResponseStatus responseStatus, T data, Long total) {
        super(responseStatus.code(), responseStatus.info(), data);
        this.total = total;
    }

    public ResponsePagedEntity(@NotNull Object code, String info, T data, Long total) {
        super(code, info, data);
        this.total = total;
    }

    /**
     * 返回"00000"状态码，通用方法
     *
     * @param <T>   返回值类型
     * @param total 总数
     * @return ResponseEntity<T extends Collection> super ?
     */
    public static <T extends Collection<?>> ResponseEntity<T> success(T data, Long total) {
        return new ResponsePagedEntity<>(ResponseStatus.COSMO_00000, data, total);
    }
}
